﻿@page "/Dashboard"
@using System.Globalization
@using Microsoft.AspNetCore.Mvc.Localization
@using Microsoft.AspNetCore.Mvc.Rendering
@using Guili.AdministrationService.Localization
@using Guili.AdministrationService.Web.Menus
@using Volo.Abp.AspNetCore.Mvc.UI.Layout
@using Volo.Abp.AspNetCore.Mvc.UI.Widgets
@using Volo.Abp.AuditLogging.Web.Pages.Shared.Components.AverageExecutionDurationPerDayWidget
@using Volo.Abp.AuditLogging.Web.Pages.Shared.Components.ErrorRateWidget
@inject IHtmlLocalizer<AdministrationServiceResource> L
@inject IWidgetManager WidgetManager
@model Guili.AdministrationService.Web.Pages.TenantDashboardModel
@{
    ViewBag.PageTitle = "Dashboard";
}
@inject IPageLayout PageLayout
@{
    PageLayout.Content.Title = L["Dashboard"].Value;
    PageLayout.Content.BreadCrumb.Add(L["Menu:Dashboard"].Value);
    PageLayout.Content.MenuItemName = AdministrationServiceMenus.TenantDashboard;
}

@section scripts {
    <abp-script src="/Pages/TenantDashboard.js" />
}

@section styles {
    <abp-style src="/Pages/TenantDashboard.css" />
}

<abp-card>
    <abp-card-body>
        <form method="get" id="DashboardFilterForm">
            <abp-row h-align="Center">
                <div class="input-daterange input-group input-group-sm" id="datepicker">
                    <span class="input-group-text">@L["StartDate"].Value</span>
                    <input type="text"
                            class="form-control"
                            name="StartDate"
                            value="@DateTime.Now.AddMonths(-1).Date.ToString(CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern)" />

                    <span class="input-group-text">@L["EndDate"].Value</span>
                    <input type="text"
                            class="form-control"
                            name="EndDate"
                            value="@DateTime.Now.Date.ToString(CultureInfo.CurrentUICulture.DateTimeFormat.ShortDatePattern)" />
                    <abp-button button-type="Primary" icon="refresh" size="Medium" type="Submit" text="@L["Refresh"].Value" />
                </div>
            </abp-row>
        </form>
    </abp-card-body>
</abp-card>

<div id="TenantDashboardWidgetsArea" data-widget-filter="#DashboardFilterForm">
    <abp-row class="mt-5">
        @if (await WidgetManager.IsGrantedAsync(typeof(AuditLoggingErrorRateWidgetViewComponent)))
        {
            <abp-column size="_4">
                @await Component.InvokeAsync(typeof(AuditLoggingErrorRateWidgetViewComponent))
            </abp-column>
        }
        @if (await WidgetManager.IsGrantedAsync(typeof(AuditLoggingAverageExecutionDurationPerDayWidgetViewComponent)))
        {
            <abp-column size="_4">
                @await Component.InvokeAsync(typeof(AuditLoggingAverageExecutionDurationPerDayWidgetViewComponent))
            </abp-column>
        }
    </abp-row>
</div>